package studentinformationmanagementsystem.dao.impl;

import studentinformationmanagementsystem.dao.BaseDao;
import studentinformationmanagementsystem.dao.TakeACourseDao;
import studentinformationmanagementsystem.entity.Major;
import studentinformationmanagementsystem.entity.TakeACourse;

import java.util.List;

/**
 * @author 苗庆
 * @version 1.0
 */
public class TakeACoureDaolmpl extends BaseDao implements TakeACourseDao {


    /**
     * 对选课信息进行添加
     * @param takeACourse  选课对象
     * @return  受影响的记录行数
     */
    @Override
    public int insert(TakeACourse takeACourse) {

        String sql = "INSERT INTO `t_takeacourse` (`studid`, `temporaryclasstableid`, `achievement`) VALUES (?, ?,?)";
        return super.update(sql,takeACourse.getStudid(),takeACourse.getTemporaryclasstableid(),takeACourse.getAchievement());

    }



    /**
     *  根据ID更新选课信息
     * @param takeACourse  选课对象
     * @return 受影响的记录行数
     */
    @Override
    public int update(TakeACourse takeACourse) {
        String sql = "UPDATE `t_takeacourse` SET `studid` = ? , `temporaryclasstableid` = ?,`achievement` = ? WHERE `takeacourseid` = ? ";
        return super.update(sql,takeACourse.getStudid(),takeACourse.getTemporaryclasstableid(),takeACourse.getAchievement(),takeACourse.getTakeacourseid());
    }


    /**
     *  根据ID删除选课
     * @param takeACourse 选课ID
     * @return 受影响的记录行数
     */
    @Override
    public int delete(TakeACourse takeACourse) {
        String sql = "DELETE FROM `t_takeacourse` WHERE `takeacourseid` = ?";
        return super.update(sql, takeACourse.getTakeacourseid());
    }


    /**
     * 查询所有选课信息
     * @return 所有选课信息
     */
    @Override
    public List<TakeACourse> queryAll() {
        String sql = "SELECT * FROM `t_takeacourse`";
        return super.queryForList(TakeACourse.class, sql);
    }


    /**
     * 根据选课ID查询选课信息
     * @param takeACourse 选课ID
     * @return 选课信息
     */
    @Override
    public TakeACourse queryById(TakeACourse takeACourse) {
        String sql = "SELECT * FROM `t_takeacourse` WHERE `takeacourseid` = ?";
        return super.queryForOne(TakeACourse.class, sql, takeACourse.getTakeacourseid());
    }


    /**
     * 根据学生表id查询选课信息
     * @param takeACourse 学生表id
     * @return 选课信息
     */
    @Override
    public TakeACourse queryBystudid(TakeACourse takeACourse) {
        String sql = "SELECT * FROM `t_takeacourse` WHERE `studid` = ?";
        return super.queryForOne(TakeACourse.class, sql, takeACourse.getStudid());
    }


    /**
     * 根据选课临时班级表id查询选课信息
     * @param takeACourse 选课临时班级表id
     * @return 1个选课信息
     */
    @Override
    public TakeACourse queryBytemporaryclasstableid(TakeACourse takeACourse) {
        String sql = "SELECT * FROM `t_takeacourse` WHERE `temporaryclasstableid` = ?";
        return super.queryForOne(TakeACourse.class, sql, takeACourse.getTemporaryclasstableid());
    }



    /**
     * 根据选课临时班级表id查询选课信息
     * @param takeACourse 选课临时班级表id
     * @return 返回多个课信息
     */
    @Override
    public List<TakeACourse> queryBytemporaryclasstableId(TakeACourse takeACourse) {
        String sql = "SELECT * FROM `t_takeacourse` WHERE `temporaryclasstableid` = ?";
        return super.queryForList(TakeACourse.class, sql,takeACourse.getTemporaryclasstableid());
    }

    /**
     * 根据学生表id查询选课信息
     * @param takeACourse 学生表id
     * @return 返回多个选课信息
     */
    @Override
    public List<TakeACourse> queryBystudidC(TakeACourse takeACourse) {
        String sql = "SELECT * FROM `t_takeacourse` WHERE `studid` = ?";
        return super.queryForList(TakeACourse.class, sql,takeACourse.getStudid());
    }

    /**
     *
     * @param takeACourse
     * @return
     */
    @Override
    public TakeACourse queryBytemporaryclasstableidAndstudid(TakeACourse takeACourse) {
        String sql = "SELECT * FROM `t_takeacourse` WHERE `studid` = ? and `temporaryclasstableid` = ?";
        return super.queryForOne(TakeACourse.class, sql, takeACourse.getStudid(),takeACourse.getTemporaryclasstableid());
    }


}
